//
//  FSCLeftView.swift
//  FamiliesSchoolConnection
//
//  Created by 花花蔡 on 2016/12/24.
//  Copyright © 2016年 com.HuaHuaCai. All rights reserved.
//

import UIKit

class FSCLeftView: UIViewController {

    let btnH = screenHeight * 0.071
    
    var aboutUsBtnBlock:( () -> () )?
    var scheduleBtnBlock:( () -> () )?
    var feedBackBtnBlock:( () -> () )?
    var setUpBtnBlock:( () -> () )?
    var exitBtnBlock:( () -> () )?
    
    override func viewDidLoad() {
    }
    
//MARK:加载UI

    func addLeftView(VC:UIViewController) -> Void {
        
        let btnName = ["课程表","关于我们","意见反馈","设置","退出"]
        let imageName = ["class_schedule","about_us","feedback","设置","log_out"]
        for item in 0 ..< btnName.count {
            let Btn = UIButton(type: .custom)
            Btn.frame = CGRect(x: 0, y: Int(260.0 * kWidth_ScaleH + (btnH*CGFloat(item))), width: Int(leftViewWidth), height: Int(btnH))
            Btn.setTitle(btnName[item], for: .normal)
            Btn.setTitleColor(UIColor.lightGray, for: .normal)
            Btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)
            let img = UIImage(named: imageName[item])
            Btn.setImage(img, for: .normal)
            Btn.tag = btnBaseTAG + item
            Btn.addTarget(self, action: #selector(btnClicked(btn:)), for: .touchUpInside)
            Btn.contentHorizontalAlignment = .left
            Btn.contentVerticalAlignment = .center
            Btn.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0)
            Btn.titleEdgeInsets = UIEdgeInsetsMake(0, 50, 0, 0)
            let bkImg = UIImage.imageWithColor(color: UIColor(white: 0.8, alpha: 0.8))
            Btn.setBackgroundImage(bkImg!, for: .highlighted)
            
            VC.view.addSubview(Btn)
            
        }
        
    }
    
    
//MARK:btn点击事件
    
    func btnClicked(btn:UIButton) -> Void {
       
        switch btn.tag - btnBaseTAG {
        case 0:
            scheduleBtnBlock?() //课程表
        case 1:
            aboutUsBtnBlock?()  //关于我们
        case 2:
            feedBackBtnBlock?() //意见反馈
        case 3:
            setUpBtnBlock?()    //设置
        case 4:
            exitBtnBlock?()     //推出
            
        default:
            break
        }
    }

    
}
